/**
 * Copyright &copy; 2017-2018 <a href="http://www.webcsn.com">webcsn</a> All rights reserved.
 *
 * @author hermit
 * @date 2018-04-17 10:54:58
 */
package com.wxmp.wxcms.ctrl;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wxmp.core.common.BaseCtrl;
import com.wxmp.core.util.AjaxResult;
import com.wxmp.wxapi.process.MpAccount;
import com.wxmp.wxapi.process.WxMemoryCacheClient;
import com.wxmp.wxcms.domain.UserOrder;
import com.wxmp.wxcms.domain.UserShare;
import com.wxmp.wxcms.service.AccountService;
import com.wxmp.wxcms.service.RegisterUserService;
import com.wxmp.wxcms.service.UserOrderService;
import com.wxmp.wxcms.service.UserShareService;

/**
 *
 * @author fuziKong
 * @version 2.0
 * @date 2018-06-23 10:54:58
 */
@Controller
@RequestMapping("/userOrder")
public class UserOrderCtrl extends BaseCtrl {

	@Autowired
	private UserOrderService entityService;


	/**
	 * 分页查询
	 * @param searchEntity
	 * @return
	 */
	@RequestMapping(value = "/listForPage")
	@ResponseBody
	public AjaxResult listForPage(UserOrder searchEntity) {
		List<UserOrder> list = entityService.getUserOrderListByPage(searchEntity);
		if (CollectionUtils.isEmpty(list)) {
			return AjaxResult.success();
		}
		return getResult(searchEntity,list);
	}
	

	/**
	 * 修改/添加
	 * @param entity
	 * @return
	 */
	@RequestMapping(value = "/update")
	@ResponseBody
	public AjaxResult update(UserOrder entity){
				entityService.add(entity);
				//分享成功延长试用天数
//				MpAccount mpAccount = WxMemoryCacheClient.getMpAccount();//获取缓存中的唯一账号
//				Integer addDays = accountService.getAddDays(mpAccount.getAccount());
//				registerUserService.updateUseDay(addDays, entity.getUserId());
				return AjaxResult.saveSuccess();
	}


	/**
	 * 批量删除
	 * @param String[] ids
	 * @return
	 */
	@RequestMapping(value = "/deleteBatchIds")
	@ResponseBody
	public AjaxResult deleteBatchIds(String [] ids) {
		entityService.deleteBatchIds(ids);
		return AjaxResult.deleteSuccess();
	}
}